package com.wms.controller;

import com.wms.common.CallBack;
import com.wms.common.Response;
import com.wms.domain.GoodsDomain;
import com.wms.service.information.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "商品信息")
@RequestMapping(path = "/Goods/")
@RestController
public class Goods {
    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value="编辑商品信息")
    @RequestMapping(path="addOrUpdateGoods",method= RequestMethod.POST)
    public Response addOrUpdateGoods(@RequestBody GoodsDomain goodsDomain){
        return new CallBack() {
            @Override
            protected Object run() {
                return goodsService.addOrUpdateGoods(goodsDomain);
            }
        }.execute();
    }

    @ApiOperation(value="删除商品")
    @RequestMapping(path="deleteGoods",method= RequestMethod.POST)
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public Response deleteGoods(final Long id){
        return new CallBack() {
            @Override
            protected Object run() {
                return goodsService.deleteGoods(id);
            }
        }.execute();
    }

    @ApiOperation(value="查询商品")
    @RequestMapping(path="getGoodsPage",method= RequestMethod.POST)
    public Response getGoodsPage(@RequestBody GoodsDomain goodsDomain){
        return new CallBack() {
            @Override
            protected Object run() {
                return goodsService.getGoodsPage(goodsDomain);
            }
        }.execute();
    }
}
